package cn.edu.zzu.demo01Thread;

/**
 * 守护线程
 * 用户线程
 */
public class TestDeamonThread {
    public static void main(String[] args) {
        Thread you = new Thread(new You(), "小米");
        Thread god = new Thread(new God(), "上帝");

        god.setDaemon(true); // 设置该线程为守护线程，之后其他所有线程都结束时候，它才会结束
        you.start();
        god.start();

    }
}

class  You implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 36500; i++) {
            System.out.println("活了"+i+"天");
        }
        System.out.println("baybay!");
    }
}

class  God implements Runnable{

    @Override
    public void run() {
            while (true){
                System.out.println("守护线程！");
            }
    }
}